
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>栅格数据裁剪 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="打开Shapefile文件的正确方式.html" />
    
    
    <link rel="prev" href="栅格数据投影转换.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../Python基础/">
            
                <a href="../../Python基础/">
            
                    
                    Python基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../../Python基础/Python环境搭建及基本数据类型.html">
            
                <a href="../../Python基础/Python环境搭建及基本数据类型.html">
            
                    
                    Python环境搭建及基本数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../../Python基础/运算符及字符串.html">
            
                <a href="../../Python基础/运算符及字符串.html">
            
                    
                    运算符及字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../../Python基础/序列与字典.html">
            
                <a href="../../Python基础/序列与字典.html">
            
                    
                    序列与字典
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../../Python基础/流程控制语句.html">
            
                <a href="../../Python基础/流程控制语句.html">
            
                    
                    流程控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../../Python基础/函数.html">
            
                <a href="../../Python基础/函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../../Python基础/面向对象编程初识.html">
            
                <a href="../../Python基础/面向对象编程初识.html">
            
                    
                    面向对象编程初识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../../Python基础/面向对象编程高级.html">
            
                <a href="../../Python基础/面向对象编程高级.html">
            
                    
                    面向对象编程高级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../../Python基础/Python科学计算.html">
            
                <a href="../../Python基础/Python科学计算.html">
            
                    
                    Python科学计算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../../Python基础/空间数据处理环境搭建.html">
            
                <a href="../../Python基础/空间数据处理环境搭建.html">
            
                    
                    空间数据处理环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../空间数据基础/">
            
                <a href="../../空间数据基础/">
            
                    
                    空间数据基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../空间数据基础/空间参考系统.html">
            
                <a href="../../空间数据基础/空间参考系统.html">
            
                    
                    空间参考系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../空间数据基础/地图投影.html">
            
                <a href="../../空间数据基础/地图投影.html">
            
                    
                    地图投影
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../空间数据基础/空间数据.html">
            
                <a href="../../空间数据基础/空间数据.html">
            
                    
                    空间数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../">
            
                <a href="../">
            
                    
                    GDAL空间数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../GDAL简介.html">
            
                <a href="../GDAL简介.html">
            
                    
                    GDAL简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../GDAL数据基本操作.html">
            
                <a href="../GDAL数据基本操作.html">
            
                    
                    GDAL数据基本操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="打开栅格数据的正确方式.html">
            
                <a href="打开栅格数据的正确方式.html">
            
                    
                    打开栅格数据的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.2" data-path="栅格数据格式转换.html">
            
                <a href="栅格数据格式转换.html">
            
                    
                    栅格数据格式转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.3" data-path="栅格数据创建与保存.html">
            
                <a href="栅格数据创建与保存.html">
            
                    
                    栅格数据创建与保存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.4" data-path="读取HDF或者NetCDF格式的栅格数据.html">
            
                <a href="读取HDF或者NetCDF格式的栅格数据.html">
            
                    
                    读取HDF或者NetCDF格式的栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.5" data-path="栅格数据投影转换.html">
            
                <a href="栅格数据投影转换.html">
            
                    
                    栅格数据投影转换
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.2.6" data-path="栅格数据裁剪.html">
            
                <a href="栅格数据裁剪.html">
            
                    
                    栅格数据裁剪
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.7" data-path="打开Shapefile文件的正确方式.html">
            
                <a href="打开Shapefile文件的正确方式.html">
            
                    
                    打开Shapefile文件的正确方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.8" data-path="创建Shapefile文件并写入数据.html">
            
                <a href="创建Shapefile文件并写入数据.html">
            
                    
                    创建Shapefile文件并写入数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2.9" data-path="矢量数据投影转换.html">
            
                <a href="矢量数据投影转换.html">
            
                    
                    矢量数据投影转换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Fiona矢量数据处理/REDAME.md">
            
                <span>
            
                    
                    Fiona矢量数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                <a href="../Fiona矢量数据处理/Fiona简介及Shapefile数据读取.html">
            
                    
                    Fiona简介及Shapefile数据读取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                <a href="../Fiona矢量数据处理/使用Fiona创建Shapefile矢量数据.html">
            
                    
                    使用Fiona创建Shapefile矢量数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Rasterio栅格数据处理/README.md">
            
                <span>
            
                    
                    Rasterio栅格数据处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../Rasterio栅格数据处理/使用Rasterio读取栅格数据.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio读取栅格数据.html">
            
                    
                    使用Rasterio读取栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.2" data-path="../Rasterio栅格数据处理/使用Rasterio创建栅格数据.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio创建栅格数据.html">
            
                    
                    使用Rasterio创建栅格数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4.3" data-path="../Rasterio栅格数据处理/使用Rasterio做投影变换.html">
            
                <a href="../Rasterio栅格数据处理/使用Rasterio做投影变换.html">
            
                    
                    使用Rasterio做投影变换
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >栅格数据裁剪</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6805;&#x683C;&#x6570;&#x636E;&#x88C1;&#x526A;">&#x6805;&#x683C;&#x6570;&#x636E;&#x88C1;&#x526A;</h1>
<p>&#x4F5C;&#x8005;&#xFF1A;&#x963F;&#x632F;</p>
<p>&#x90AE;&#x7BB1;&#xFF1A;tanzhenyugis@163.com</p>
<p>&#x535A;&#x5BA2;&#xFF1A;<a href="https://blog.csdn.net/theonegis/article/details/80089375" target="_blank">https://blog.csdn.net/theonegis/article/details/80089375</a></p>
<p>&#x4FEE;&#x6539;&#x65F6;&#x95F4;&#xFF1A;2019-03-22</p>
<p>&#x58F0;&#x660E;&#xFF1A;&#x672C;&#x6587;&#x4E3A;&#x535A;&#x4E3B;&#x539F;&#x521B;&#x6587;&#x7AE0;&#xFF0C;&#x8F6C;&#x8F7D;&#x8BF7;&#x6CE8;&#x660E;&#x539F;&#x6587;&#x51FA;&#x5904;</p>
<hr>
<p>&#x5728;&#x8FDB;&#x884C;&#x9065;&#x611F;&#x5F71;&#x50CF;&#x5904;&#x7406;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6211;&#x4EEC;&#x7ECF;&#x5E38;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x88C1;&#x526A;&#x7684;&#x5DE5;&#x4F5C;&#xFF0C;&#x6765;&#x770B;&#x770B;&#x5982;&#x4F55;&#x4F7F;&#x7528;GDAL&#x5DE5;&#x5177;&#x8FDB;&#x884C;&#x8FD9;&#x9879;&#x64CD;&#x4F5C;&#x5427;&#xFF01;</p>
<p>&#x53C2;&#x8003;&#x8D44;&#x6599;&#xFF1A;</p>
<ol>
<li><a href="https://www.gdal.org/gdalwarp.html" target="_blank">GDAL: gdalwarp</a></li>
<li><a href="https://www.gdal.org/gdal_translate.html" target="_blank">GDAL: gdal_translate</a></li>
<li><a href="https://gdal.org/python/" target="_blank">GDAL/OGR Python API</a></li>
</ol>
<h2 id="&#x4F7F;&#x7528;gdal&#x547D;&#x4EE4;">&#x4F7F;&#x7528;GDAL&#x547D;&#x4EE4;</h2>
<p>GDAL&#x63D0;&#x4F9B;&#x4E86;&#x4E24;&#x4E2A;&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x5F71;&#x50CF;&#x7684;&#x88C1;&#x526A;&#xFF1A;<code>gdalwarp</code>&#x548C;<code>gdal_translate</code>&#xFF0C;&#x4E24;&#x4E2A;&#x547D;&#x4EE4;&#x4E2D;&#x6211;&#x66F4;&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x540E;&#x8005;&#x3002;</p>
<p><code>gdalwarp</code>&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>-te</code>&#x5236;&#x5B9A;&#x88C1;&#x526A;&#x8303;&#x56F4;&#x3002;&#x9ED8;&#x8BA4;&#x662F;&#x5728;&#x539F;&#x6570;&#x636E;&#x7684;&#x5750;&#x6807;&#x7CFB;&#x4E0B;&#x7684;<code>xmin ymin xmax ymax</code>&#xFF0C;&#x5F53;&#x7136;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>-te_srs</code>&#x53C2;&#x6570;&#x6307;&#x5B9A;<code>-te</code>&#x53C2;&#x6570;&#x6240;&#x5728;&#x7684;&#x5750;&#x6807;&#x7CFB;&#x3002;</p>
<p>&#x4E3A;&#x4EC0;&#x4E48;&#x4E0D;&#x63A8;&#x8350;<code>gdalwarp</code>&#x547D;&#x4EE4;&#x5462;&#xFF1F;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;<code>gdalwarp</code>&#x547D;&#x4EE4;&#x53EA;&#x63D0;&#x4F9B;&#x4E86;&#x6839;&#x636E;&#x5750;&#x6807;&#x7CFB;&#x7684;&#x8303;&#x56F4;&#x8FDB;&#x884C;&#x88C1;&#x526A;&#xFF0C;&#x800C;&#x4E0D;&#x652F;&#x6301;&#x6839;&#x636E;&#x884C;&#x5217;&#x53F7;&#x7684;&#x88C1;&#x526A;&#x3002;&#x8FD9;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6C42;&#x52A9;&#x4E8E;<code>gdal_translate</code>&#x547D;&#x4EE4;&#x3002;</p>
<p><code>gdal_transalte</code>&#x547D;&#x4EE4;&#x5373;&#x652F;&#x6301;&#x4F7F;&#x7528;<code>-srcwin</code>&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x884C;&#x5217;&#x53F7;&#x8303;&#x56F4;<code>xoff yoff xsize ysize</code>&#xFF0C;&#x4E5F;&#x652F;&#x6301;&#x4F7F;&#x7528;<code>-projwin</code>&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x539F;&#x6570;&#x636E;&#x5750;&#x6807;&#x7CFB;&#x4E0B;&#x7684;&#x8303;&#x56F4;<code>ulx uly lrx lry</code>&#x3002;&#x540C;&#x65F6;&#x63D0;&#x4F9B;&#x53C2;&#x6570;<code>-projwin_srs</code>&#x53EF;&#x4EE5;&#x7528;&#x4E8E;&#x6307;&#x5B9A;<code>-projwin</code>&#x53C2;&#x6570;&#x6240;&#x5728;&#x7684;&#x5750;&#x6807;&#x7CFB;&#xFF0C;&#x5373;&#x8DDF;<code>gdalwarp</code>&#x547D;&#x4EE4;&#x4E2D;&#x7684;<code>-te_srs</code>&#x53C2;&#x6570;&#x7C7B;&#x4F3C;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7ED9;&#x51FA;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#xFF1A;</p>
<p><code>gdal_translate -of &quot;GTiff&quot; -srcwin 10 10 256 256 -a_scale 1 HDF4_EOS:EOS_GRID:&quot;MOD09GA.A2018349.h26v05.006.2018351030314.hdf&quot;:MODIS_Grid_500m_2D:sur_refl_b01_1 sr_1.tif</code></p>
<p>&#x8FD9;&#x884C;&#x547D;&#x4EE4;&#x5C06;MODIS&#x6570;&#x636E;&#x4E2D;&#x7684;&#x53CD;&#x5C04;&#x7387;&#x7684;&#x7B2C;&#x4E00;&#x6CE2;&#x6BB5;&#x8FDB;&#x884C;&#x88C1;&#x526A;&#xFF0C;&#x8D77;&#x70B9;&#x4E3A;&#x7B2C;10&#x884C;&#x7B2C;10&#x5217;&#xFF0C;&#x8F93;&#x51FA;&#x5927;&#x5C0F;&#x4E3A;256$\times$255&#xFF0C;&#x8F93;&#x51FA;&#x683C;&#x5F0F;&#x4E3A;TIFF&#x3002;</p>
<p>&#x6CE8;&#x610F;&#x8FD9;&#x884C;&#x547D;&#x4EE4;&#x6709;&#x4E00;&#x4E2A;<code>-a_scale 1</code>&#x53C2;&#x6570;&#xFF0C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x4E86;&#x88C1;&#x526A;&#x8FC7;&#x7A0B;&#x4E0D;&#x8981;&#x5BF9;DN&#x503C;&#x8FDB;&#x884C;&#x7F29;&#x653E;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x52A0;&#x8FD9;&#x4E2A;&#x503C;&#x5F97;&#x8BDD;&#xFF0C;&#x8F93;&#x51FA;&#x56FE;&#x50CF;&#x7684;DN&#x503C;&#x4F1A;&#x88AB;&#x6839;&#x636E;&#x539F;&#x6570;&#x636E;&#x7684;<code>Scale=10000</code>&#x653E;&#x5927;10000&#x500D;&#x3002;</p>
<h2 id="&#x4F7F;&#x7528;python&#x4EE3;&#x7801;">&#x4F7F;&#x7528;Python&#x4EE3;&#x7801;</h2>
<p>&#x5BF9;&#x4E8E;&#x4F7F;&#x7528;Python&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x88C1;&#x526A;&#xFF0C;&#x6211;&#x4EEC;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li>&#x7B2C;&#x4E00;&#x5C31;&#x662F;&#x5BF9;&#x547D;&#x4EE4;&#x884C;&#x5BF9;&#x5E94;&#x7684;&#x501F;&#x53E3;&#x76F4;&#x63A5;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#x3002;&#x8FD9;&#x4E2A;&#x6700;&#x76F4;&#x63A5;&#x6700;&#x7B80;&#x5355;&#x3002;</li>
<li>&#x7B2C;&#x4E8C;&#x5C31;&#x662F;&#x9996;&#x5148;&#x81EA;&#x5DF1;&#x9009;&#x62E9;&#x51FA;&#x9700;&#x8981;&#x88C1;&#x526A;&#x7684;&#x533A;&#x57DF;&#xFF0C;&#x7136;&#x540E;&#x8BA1;&#x7B97;&#x88C1;&#x526A;&#x533A;&#x57DF;&#x7684;GeoTransform&#x7684;&#x7CFB;&#x6570;&#xFF0C;&#x6700;&#x540E;&#x5C06;&#x6295;&#x5F71;&#x548C;GeoTransform&#x7CFB;&#x6570;&#x8D4B;&#x503C;&#x7ED9;&#x88C1;&#x526A;&#x5B50;&#x533A;&#x57DF;&#xFF0C;&#x5199;&#x5165;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x3002;</li>
</ul>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;<a href="https://blog.csdn.net/theonegis/article/details/80304873" target="_blank">GDAL&#x4E2D;&#x4F7F;&#x7528;&#x4E86;&#x516D;&#x53C2;&#x6570;&#x6A21;&#x578B;&#x5B58;&#x50A8;GeoTransform&#x53C2;&#x6570;</a>&#xFF0C;&#x5982;&#x679C;&#x8FDB;&#x884C;&#x77E9;&#x5F62;&#x88C1;&#x526A;&#x7684;&#x8BDD;&#xFF0C;&#x53EA;&#x6709;<code>GT(0)</code>&#x548C;<code>GT(3)</code>&#x53C2;&#x6570;&#x4F1A;&#x6709;&#x53D8;&#x5316;&#xFF0C;&#x5373;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x8BA1;&#x7B97;&#x88C1;&#x526A;&#x4EE5;&#x540E;&#x7684;&#x5DE6;&#x4E0A;&#x89D2;&#x5750;&#x6807;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7ED9;&#x51FA;&#x4F7F;&#x7528;Python&#x5BF9;MODIS&#x53CD;&#x5C04;&#x7387;&#x7684;&#x7B2C;&#x4E00;&#x6CE2;&#x6BB5;&#x8FDB;&#x884C;&#x88C1;&#x526A;&#x7684;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-Python"><span class="hljs-keyword">from</span> osgeo <span class="hljs-keyword">import</span> gdal
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-comment"># API&#x53C2;&#x8003;&#xFF1A;https://gdal.org/python/</span>
<span class="hljs-comment"># GDAL&#x547D;&#x4EE4;&#x884C;&#x53C2;&#x8003;&#xFF1A;https://www.gdal.org/gdal_translate.html</span>
image_name = (<span class="hljs-string">&apos;HDF4_EOS:EOS_GRID:&apos;</span>
              <span class="hljs-string">&apos;&quot;MOD09GA.A2018349.h26v05.006.2018351030314.hdf&quot;:&apos;</span>
              <span class="hljs-string">&apos;MODIS_Grid_500m_2D:sur_refl_b01_1&apos;</span>)

<span class="hljs-comment"># &#x7B2C;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x4E5F;&#x662F;&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;GDAL&#x547D;&#x4EE4;&#x884C;&#x5BF9;&#x5E94;&#x7684;Python&#x65B9;&#x6CD5;</span>
src: gdal.Dataset = gdal.Open(image_name)
src = gdal.Translate(<span class="hljs-string">&apos;cropped_with_translate.tif&apos;</span>, src, srcWin=[<span class="hljs-number">10</span>, <span class="hljs-number">10</span>, <span class="hljs-number">256</span>, <span class="hljs-number">256</span>],
                     options=[<span class="hljs-string">&apos;-a_scale&apos;</span>, <span class="hljs-string">&apos;1&apos;</span>])
<span class="hljs-keyword">del</span> src

<span class="hljs-comment"># &#x7B2C;&#x4E8C;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x81EA;&#x5DF1;&#x9009;&#x62E9;&#x51FA;&#x9700;&#x8981;&#x7684;&#x50CF;&#x7D20;&#xFF0C;&#x7136;&#x540E;&#x81EA;&#x5DF1;&#x786E;&#x5B9A;&#x88C1;&#x526A;&#x4EE5;&#x540E;&#x7684;&#x7A7A;&#x95F4;&#x53C2;&#x8003;&#x5173;&#x7CFB;&#xFF0C;&#x5E76;&#x5199;&#x5165;&#x5230;&#x8F93;&#x51FA;&#x6587;&#x4EF6;</span>
src: gdal.Dataset = gdal.Open(image_name)
band: gdal.Band = src.GetRasterBand(<span class="hljs-number">1</span>)
subset: np.ndarray = band.ReadAsArray(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>, <span class="hljs-number">256</span>, <span class="hljs-number">256</span>)

driver: gdal.Driver = gdal.GetDriverByName(<span class="hljs-string">&apos;GTiff&apos;</span>)
dst: gdal.Dataset = driver.Create(<span class="hljs-string">&apos;cropped_from_scratch.tif&apos;</span>, <span class="hljs-number">256</span>, <span class="hljs-number">256</span>, <span class="hljs-number">1</span>, gdal.GDT_Int16)
dst.SetProjection(src.GetProjection())
trans = list(src.GetGeoTransform())
trans[<span class="hljs-number">0</span>] -= <span class="hljs-number">-10</span> * trans[<span class="hljs-number">1</span>]
trans[<span class="hljs-number">3</span>] -= <span class="hljs-number">-10</span> * trans[<span class="hljs-number">5</span>]
dst.SetGeoTransform(tuple(trans))

band: gdal.Band = dst.GetRasterBand(<span class="hljs-number">1</span>)
band.WriteArray(subset)
band.FlushCache()
<span class="hljs-keyword">del</span> src
<span class="hljs-keyword">del</span> dst
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="栅格数据投影转换.html" class="navigation navigation-prev " aria-label="Previous page: 栅格数据投影转换">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="打开Shapefile文件的正确方式.html" class="navigation navigation-next " aria-label="Next page: 打开Shapefile文件的正确方式">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"栅格数据裁剪","level":"1.4.2.6","depth":3,"next":{"title":"打开Shapefile文件的正确方式","level":"1.4.2.7","depth":3,"path":"GDAL空间数据处理/GDAL数据基本操作/打开Shapefile文件的正确方式.md","ref":"GDAL空间数据处理/GDAL数据基本操作/打开Shapefile文件的正确方式.md","articles":[]},"previous":{"title":"栅格数据投影转换","level":"1.4.2.5","depth":3,"path":"GDAL空间数据处理/GDAL数据基本操作/栅格数据投影转换.md","ref":"GDAL空间数据处理/GDAL数据基本操作/栅格数据投影转换.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"GDAL空间数据处理/GDAL数据基本操作/栅格数据裁剪.md","mtime":"2019-03-22T19:26:00.540Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-03-22T20:04:12.549Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

